//
//  SplashWindowController.m
//  Personal Passlock
//
//  Created by 杨岑 on 5/6/15.
//  Copyright (c) 2015 杨岑. All rights reserved.
//

#import "SplashWC.h"
#import "DocumentListWC.h"
#import "AppiCloud.h"
#import "NSAlert+Ext.h"


@interface SplashWC ()
@property DocumentListWC* docListWindowController;
@end

@implementation SplashWC

- (void)awakeFromNib
{
    [self.busy startAnimation:self];
    
    [[AppiCloud singleton] setupiCloud:^(BOOL success) {
        dispatch_async(dispatch_get_main_queue(), ^{
           if (success)
           {
               self.docListWindowController = [[DocumentListWC alloc] initWithWindowNibName:@"DocList"];
               [self.docListWindowController loadWindow];
               [self.docListWindowController showWindow:nil];
               [[self window] close];
           }
           else
           {
               NSAlert* alert = [[NSAlert alloc] init];
               [alert addButtonWithTitle:@"OK"];
               alert.messageText = @"iCloud Not Available";
               alert.informativeText = @"It seems iCloud is not available.";
               [alert runModalSheet:self.window completionHandler:^(NSModalResponse returnCode) {
                   [[NSApplication sharedApplication] terminate:self];
               }];
           }
        });
    }];
}

@end
